{include file="public/_meta" /}
{include file="public/_nav" /}

<div class="container body">
    <div class="col-xs-2">
        {include file="public/_left" /}
    </div>
    <div class="col-xs-10">
        <ol class="breadcrumb">
            导航位置：<li><a href="#">文章添加</a></li>
        </ol>
        <h2>文章添加</h2>
        <form action="#">
            <div class="form-group">
                <label for="title" class="control-label">标题</label>
                <input type="text" class="form-control" id="title" name="title" placeholder="文章标题" />
            </div>
            <div class="form-group">
                <label for="cateid" class="control-label">所属栏目</label>
                <select class="form-control" id="cateid" name="cateid">
                    <option value="">请选择</option>
                    {volist name="catesInfo" id="vo"}
                    <option value="{$vo.id}">{$vo.catename}</option>
                    {/volist}
                </select>
            </div>
            <div class="form-group">
                <label for="uedit" class="control-label">内容</label>
                <textarea id="uedit" name="content"></textarea>
            </div>
            <div class="form-group">
                <button class="btn btn-primary" id="articleadd">添加</button>
                <button class="btn btn-warning" type="reset">重置</button>
            </div>
        </form>
    </div>
</div>

{include file="public/_js" /}
<script>
    UE.getEditor('uedit', {
        toolbars:[
            ['source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'strikethrough',
                'superscript', 'subscript', '|', 'forecolor', 'backcolor', '|', 'insertorderedlist',
                'insertunorderedlist', '|', 'fontfamily', 'fontsize', '|', 'justifyleft', 'justifyright',
                'justifycenter', 'justifyjustify', '|', 'link', 'unlink', 'anchor', '|', 'simpleupload', 'insertimage',
                'horizontal', 'date', 'time', 'inserttable']
        ],
        zIndex:0,
        initialFrameHeight:200,
        enableAutoSave:false
    });

    $('#articleadd').click(function () {
        $.ajax({
            url:"{:url('admin/home/articleadd')}",
            type:'post',
            data:$('form').serialize(),
            dataType:'json',
            success:function (data) {
                console.log(data);
                if (data.code == 1) {
                    layer.msg(data.msg, {
                        icon:6,
                        time:2000
                    },function () {
                        location.href = data.url;
                    });
                }else {
                    layer.open({
                        title:'文章添加失败',
                        content:data.msg,
                        skin:'layui-layer-lan',
                        icon:5,
                        anim:6
                    });
                }
            }
        });
        return false;
    });
</script>
</body>
</html>